/**
 * @author LKQ
 * @date 2022/3/4 8:57
 * @description 暴力 O(n^2)
 */
public class Solution {
    public static void main(String[] args) {

    }
    public long subArrayRanges(int[] nums) {
        int n = nums.length;
        long ret = 0;
        for (int i = 0; i < n; i++) {
            int min = nums[i], max = nums[i];
            for (int j = i + 1; j < n; j++) {
                min = Math.min(min, nums[j]);
                max = Math.max(max, nums[j]);
            }
            ret += max - min;
        }
        return ret;
    }
}
